<?php
/*
 * Dans le template d'affichage des forum : 
 * afficher derniers messages envoy�s (vue, notes, auteur)
 * afficher derniers sujets cr��s (messages, vues, auteur)
 * pour chaque sujet, afficher le nombre de personnes inscrites
 * pour chaque forum, idem
 */

//FIXME : utiliser $this->translate pour le multilang
class AddForumForm extends Zend_Form
{	
	public function init()
    {
        Zend_Dojo::enableForm($this);
        
    	$decorators = array(
            array('ViewHelper'), 
            array('Description'),
            array('Errors'),
            array('Label', array('separator'=>' ', 'requiredSuffix' => ' *', 'class' => 'lefty')),
            array('HtmlTag', array('tag' => 'li')),
        );
    	
    	$title = $this->addElement('text', 'title', array(
            'filters'    => array('StringTrim', 'StringToLower'),
            'validators' => array(
                'Alnum',
                array('StringLength', false, array(3, 20)),             
            ),
            'required'   => true,
            'label'      => 'Title',
            'size'		 =>'70'
        ));
		$title->setDecorators($decorators);

		$moderators = $this->addElement('text', 'moderators', array(
            'filters'    => array('StringTrim', 'StringToLower'),
            'validators' => array(
                'Alnum',
                array('StringLength', false, array(3, 200)),             
            ),
            'required'   => true,
            'label'      => 'Moderators',
        ));
		$moderators->setDecorators($decorators); 
		
		$administrators = $this->addElement('text', 'administrators', array(
            'filters'    => array('StringTrim', 'StringToLower'),
            'validators' => array(
                'Alnum',
                array('StringLength', false, array(3, 200)),             
            ),
            'required'   => true,
            'label'      => 'Administrators',
        ));
		$administrators->setDecorators($decorators);
		
		/*$parentforum = $this->addElement('select', 'parentforum', array(
            'filters'    => array('StringTrim', 'StringToLower'),
            'validators' => array('Num'),
            'required'   => true,
            'label'      => 'Category',
        ))
        ->addMultiOptions(array('hh'=>'hello'));
       // $parentforum->addMultiOptions(array('hh'=>'hello'));
		$parentforum->setDecorators($decorators); */

    	$parentforum = new Zend_Form_Element_Select('parentforumid');
        $parentforum->setLabel('Category');
        $parentforum->setRequired(true);
        $parentforum->addValidator(new Zend_Validate_Int());
        $parentforum->addMultiOption(null, 'root category');
        
        $this->addElement($parentforum);
        
        $categories = new Forum();
        $categories = $categories->getAll();
        
        foreach ($categories as $form)
        {
            $parentforum->addMultiOption($form->id, $form->title);
        }
        
        $shortdescription = $this->addElement('textarea', 'shortdescription', array(
            'filters'    => array('StringTrim'),
            'validators' => array('Alnum'),
            'required'   => true,
            'label'      => 'Short Description',
        	'rows'		 => '3',
        	'cols'		 => '55'
        ));
        $shortdescription->setDecorators($decorators);
        
        $longdescription = $this->addElement('textarea', 'longdescription', array(
            'filters'    => array('StringTrim'),
            'validators' => array('Alnum'),
            'required'   => true,
            'label'      => 'Long description',
        	'rows'		 => '3',
        	'cols'		 => '55'
        ));        
		$longdescription->setDecorators($decorators);
		
		$accesskey = $this->addElement('text', 'accesskey', array(
            'filters'    => array('StringTrim', 'StringToLower'),
            'validators' => array(
                'Alnum',
                array('StringLength', false, array(3, 50)),             
            ),
            'required'   => true,
            'label'      => 'Access key'
        ));
		$accesskey->setDecorators($decorators);
		
		$timeupdating = $this->addElement('text', 'timeupdating', array(
            'filters'    => array('StringTrim', 'StringToLower'),
            'validators' => array(
                'Num',
                array('StringLength', false, array(1, 2)),             
            ),
            'required'   => true,
            'label'      => 'Time updating',
            'size'		 =>	'2'
        ));
		$timeupdating->setDecorators($decorators);
		
		$maxfilesizeupload = $this->addElement('text', 'maxfilesizeupload', array(
            'filters'    => array('StringTrim', 'StringToLower'),
            'validators' => array(
                'Num',
                array('StringLength', false, array(1, 3)),             
            ),
            'required'   => true,
            'label'      => 'Max file size upload',
            'size'		 => '3'
        ));
		$maxfilesizeupload->setDecorators($decorators);
		
		$accessroles = $this->addElement('text', 'accessroles', array(
            'filters'    => array('StringTrim', 'StringToLower'),
            'validators' => array(
                'Num',
                array('StringLength', false, array(1, 2)),             
            ),
            'required'   => true,
            'label'      => 'Access roles',
        ));
		$accessroles->setDecorators($decorators);
		
		$picture = $this->addElement('text', 'picture', array(
            'filters'    => array('StringTrim', 'StringToLower'),
            'validators' => array(
                'Num',
                array('StringLength', false, array(1, 2)),             
            ),
            'required'   => true,
            'label'      => 'Picture',
        ));
		$picture->setDecorators($decorators);
		
		$contentformats = $this->addElement('text', 'contentformats', array(
            'filters'    => array('StringTrim', 'StringToLower'),
            'validators' => array(
                'Num',
                array('StringLength', false, array(1, 2)),             
            ),
            'required'   => true,
            'label'      => 'Content formats',
        ));
		$contentformats->setDecorators($decorators);
        		
        $subbmit = $this->addElement('submit', 'datecreated', array(
            'required' => false,
            'ignore'   => true,
            'label'    => 'Add',
        	'value'	   =>time()
        ));

        // We want to display a 'failed authentication' message if necessary;
        // we'll do that with the form 'description', so we need to add that
        // decorator.
        $this->setDecorators(array(
            'FormElements',
            array('HtmlTag', array('tag' => 'dl', 'class' => 'zend_form')),
            array('Description', array('placement' => 'prepend')),
            'Form'
        ));
    }
}
?>